package com.liuyi.usercenterservice.config;

import lombok.Data;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 刘燚
 * @version v1.0.0
 * @Description TODO
 * @createDate：2024/6/30 15:41
 * @email liuyia2022@163.com
 */
@Configuration
@ConfigurationProperties(prefix = "spring.redis")
@Data
public class RedissonConfig {
    private String host ;
    private String port;
    private final Integer redissonDB = 0;
    @Bean
    public RedissonClient redisClient(){
        Config config = new Config();

        config.useSingleServer()
                .setAddress(String.format("redis://%s:%s",host,port))
                .setDatabase(redissonDB);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
